package com.white.server.impl;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class ServerSend implements Runnable {
    private final Socket clientSocket;
    public ServerSend(Socket clientSocket) {
        this.clientSocket = clientSocket;
    }

    @Override
    public void run() {
        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(clientSocket.getOutputStream());
            Scanner scanner = new Scanner(System.in);
            while (true) {
                System.out.println("发送客户端：");
                String msg = scanner.nextLine();
                outputStream.writeObject(msg);
                outputStream.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
            try {
                clientSocket.close();
                Client client = new Client();
                Client.IS_CONNECTION = false;
                client.reConnection();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } finally {
            if (clientSocket != null) {
                try {
                    clientSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
